/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef PROGRAMTEXTTRANSFER_H
#define PROGRAMTEXTTRANSFER_H

#include <QString>
#include <QFile>
#include <QIODevice>
#include <QTextStream>
#include <QRegExp>
#include "globalDefine.h"
#include "gSoapFoundation/soapStub.h"
#include "instructionstruct.h"
#include "instructionEnum.h"

/**
 * @brief The ProgramTextTransfer class 程序文件文本初步分析提取类
 */
class ProgramTextTransfer
{
public:
    ProgramTextTransfer(int robotIdIn);

public:

    int getDpoint(std::string fileName, int pointIndex, DPoint &pointOut);
    int recordDpoint(std::string fileName,DPoint pointIn);


    /**
     * @brief transferText 提取程序文件数据：
     * @param strFilePath　文件路径
     * @param cmdStrList_out　单行指令list
     * @param pointList_out
     * @param regPlList_out
     * @param palletStackInfo_out
     * @param vehicleDPointListOut
     * @return
     */
    int transferText(QString strFilePath,QVector <QString>& cmdStrList_out
                     ,QVector <PointPro>& pointList_out,QVector <PlRegStruct>& regPlList_out
                     ,QVector <StackInfo>& palletStackInfo_out,QMap <int, DPoint> &vehicleDPointListOut
                     ,QString &versionOut);


private:
    int readAndWriteProgramFileVersion(QString strFilePath,int &newVersionOut);
    int readProgramVersionInfo(QVector<QString> fileInfoList, QString &versionOut);
    int writeProgramVersionInfo(QString strFilePath,QString versionIn);

    /**
     * @brief readProgramDPointData         从文本中匹配读取对应索引的DP点位参数。
     * @param fileInfoList                  文本内容
     * @param vehicleDPointOut              保存DP点位数据的容器
     * @return                              0 未找到指定索引的点　1 找到指定索引的点
     */
    int readProgramDPointData(const QVector<QString> &fileInfoList,int pointIndexIn, DPoint &vehicleDPointOut);

    /**
     * @brief writeProgramDPointData        写入对应索引的DP点位参数。
     * @param fileInfoList                  文本内容
     * @param vehicleDPointOut              保存DP点位数据的容器
     * @return                              0 写入指定索引的点失败　1 写入指定索引的点成功
     */
    int addProgramDPointData(QVector<QString> &fileInfoList,DPoint vehicleDPointIn);

    /**
     * @brief addMsg  , 添加消息反馈
     * @param messageLevel
     * @param componentName
     * @param messageType
     * @param messageCode
     * @param robotId
     * @param parameter1
     * @param parameter2
     * @param parameter3
     * @param parameter4
     */
    void addMsg( int messageLevel,
                 std::string componentName,
                 std::string messageType,
                 int messageCode,
                 int robotId,
                 int parameter1 = 0,
                 int parameter2 = 0,
                 int parameter3 = 0,
                 int parameter4 = 0,
                 QString message= "");






public://new from hmi
    int readProgramAttributeQuick(const QVector <QString> fileInfoList, QString strFilePath,
                             FileInfo  &fileProInfoQuick);
    int readProgram(const QVector <QString> fileInfoList, QString strFilePath,
                             FileInfo  &fileProInfo,QVector <StackInfo> &palletStackInfo,
                    QVector <PointPro>& pointListOut,QStringList &cmdStrList,
                     QMap<int, DPoint> &vehicleDPointListOut);
    int writeProgram(const  FileInfo  &fileProInfo,const QVector <StackInfo> &palletStackInfo,
                    const QVector <PointPro>& pointList,const QStringList &cmdStrList,
                     const QMap<int, DPoint> &vehicleDPointList, const QVector<int> saveAxisUnit,
                     int globalDefaultUserNum,int globalDefaultToolNum,
                     QVector <QString> &fileInfoListOut);
    int readProgramAttribute(int startIndex,int endIndex,QVector <QString> fileInfoList, QString strFilePath,
                             FileInfo  &fileProInfo);

    int readProgramPalletInfo(int startIndex,int endIndex,QVector <QString> fileInfoList,
                              QVector <StackInfo> &palletStackInfo);
    int readProgramArmPointInfo(int startIndex,int endIndex,QVector <QString> fileInfoList,
                                QVector <PointPro>& pointListOut);
    int readProgramArmPointInfo_quick(int startIndex,int endIndex,QVector <QString> fileInfoList,
                                QVector <PointPro>& pointListOut);
    int readProgramCommandList(int startIndex,int endIndex,QVector <QString> fileInfoList,
                               QStringList &cmdStrList);
    int readProgramFileStruct(const QVector <QString> fileInfoList, int &attrStart,
                             int &tcdStart, int &tcdEnd, int &applStart, int &commandStart,
                              int &positionStart, int &endLine) ;
    int writeProgramAttribute(const FileInfo  &fileProInfo,int cmdLineSize,
                              QVector <QString> &programList);
    int writeProgramPalletInfo(  int globalDefaultUserNum,int globalDefaultToolNum,
                   const QVector <StackInfo> &palletStackInfo,
                   const QVector<int> saveAxisUnit, QVector <QString> &programList);
    int writeProgramArmPointInfo(QVector <int > saveAxisUnit,
                                 const QVector <PointPro>& getPointProList,
                                 QVector <QString> &programList);
    int writeProgramCommandList(const QStringList &cmdStrList,QVector <QString> &programList);
    /**
     * @brief writeProgramDPointData    AGV 點位數據寫入文本容器
     * @param programStrList            保存寫入文本的容器
     */
    int writeProgramDPointData(const QMap <int, DPoint> &vehicleDPointList,QVector<QString> &programStrList);

    /**
     * @brief readProgramDPointData
     * @param currentFileStr
     */
    int readProgramDPointData(int startIndex,int endIndex,QVector <QString> fileInfoList,
                              QMap<int, DPoint> &vehicleDPointListOut);

private:
    /**
     * @brief readProgramDPointData         从文本中匹配读取DP点位参数。。。？？？？？？？？？还需要测试对原来ＰｏｉｎtPro的解析是否有影响。
     * @param fileInfoList                  文本内容
     * @param vehicleDPointListOut          保存DP点位数据的容器
     * @return
     */
    int readProgramDPointData(const QVector<QString> &fileInfoList, QMap <int, DPoint> &vehicleDPointListOut);


private:
    int robotId;
    QString fileName;
};

#endif // PROGRAMTEXTTRANSFER_H
